package com.moo.order.model;

import com.moo.order.vo.OrderVo;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Project Name: moo-order
 *
 * @Author: fhw
 * File Name: order
 * Package Name: com.moo.order.model
 * Date: 2020/7/25 9:00 下午
 * Copyright (c) 2020,All Rights Reserved.
 */
@Data
@Entity
@Table(name = "t_order")
public class Order {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 店铺ID
     */
    @Column
    private Long shopId;

    /**
     * 会员ID
     */
    @Column
    private Long memberId;

    /**
     * 订单号
     */
    @Column(unique = true)
    private String orderNo;

    /**
     * 商品ID
     */
    @Column
    private Long goodsId;

    /**
     * 商品内容
     */
    @Column
    private String goodsName;

    /**
     * 商品金额
     */
    @Column
    private BigDecimal goodsAmount;

    /**
     * 订单来源
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "order_source", nullable = false)
    private OrderSource orderSource;

    /**
     * 订单金额
     */
    @Column
    private BigDecimal orderAmount;

    /**
     * 订单总额
     */
    @Column
    private BigDecimal orderTotalAmount;

    /**
     * 订单类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "order_type", nullable = false)
    private OrderType orderType;

    /**
     * 订单状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "order_status", nullable = false)
    private OrderStatus orderStatus;

    /**
     * 实付金额
     */
    @Column
    private BigDecimal payAmount;

    /**
     * 支付方式
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "pay_method")
    private OrderPayMethod payMethod;

    /**
     * 支付时间
     */
    private String payTime;

    /**
     * 支付状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "pay_status")
    private OrderPayStatus payStatus;

    /**
     * 创建时间
     */
    @Column
    private String createTime;

    /**
     * 更新时间
     */
    @Column
    private String updateTime;

    /**
     * 状态
     */
    @Column
    private Integer status;


    /**
     * model 转换 vo
     *
     * @return
     */
    public OrderVo toOrderVo() {
        OrderVo orderVo = new OrderVo();
        BeanUtils.copyProperties(this, orderVo);
        return orderVo;
    }

    /**
     * model list 转换 vo list
     *
     * @param orderList
     * @return
     */
    public List<OrderVo> toOrderVoList(List<Order> orderList) {
        if (orderList == null) {
            return null;
        }
        List<OrderVo> orderVoList = new ArrayList<>();
        orderList.forEach(Order -> {
            OrderVo orderVo = new OrderVo();
            BeanUtils.copyProperties(Order, orderVo);
            orderVoList.add(orderVo);
        });
        return orderVoList;
    }

}